<template>
	<view class="content" v-if="pageShow">
		<u-swiper :list="swiperList" height="350" circular indicatorStyle="right: 20px"
			@change="e => currentNum = e.current">
			<view slot="indicator" class="indicator-num">
				<text class="indicator-num__text">{{ currentNum + 1 }}/{{ swiperList.length }}</text>
			</view>
		</u-swiper>
		<view class="mainpadding">
			<view class="mainpadding_top ffffff radius flexleft">
				<view class="neiyong lableradius xiaohuang margin_right2">免運</view>
				<view class="xiaohui margin_right">月售{{goodsInfo.count}}</view>
				<view class="xiaohui" v-if="goodsInfo.end_num!=-1">庫存{{goodsInfo.end_num}}</view>
				<view class="xiaohui" v-if="goodsInfo.end_num==-1">不限庫存</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-if="goodsInfo.goods_sale.length">
				<view class="flexbetween">
					<view class="titletext bold hei_text">處置選擇</view>
					<view class="listbtnhuang " v-if="goodsInfo.is_cl==1" @click="clshow=true">處理選擇</view>
				</view>
				<view class="margin_top">
					<u-radio-group v-model="is_df" placement="row" circle>
						<u-radio activeColor="#ff8505" :customStyle="{marginRight: '30rpx'}" :label="item.name"
							:name="index" v-for="(item,index) in goodsInfo.goods_sale" :key="item.id"></u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="titletext bold hei_text">{{goodsInfo.name}}</view>
				<view class="hui_text margin_top2">{{goodsInfo.des}}</view>
				<view class="flexbetween margin_top" v-if="goodsInfo.is_size==1">
					<view class="flexleft" v-if="goodsInfo.shopformula.type!=2">
						<view class="main_size color_red">寬({{goodsInfo.shopformula.size}})</view>
						<view class="bghui radius margin_left2" style="padding: 20rpx 10rpx;">
							<input type="number" style="text-align: center;min-width: 180rpx;max-width: 180rpx;"
								placeholder="請輸入" class="xiaohong" v-model="wei" @blur="weiBlur">
						</view>
					</view>
					<view class="flexleft" v-if="goodsInfo.shopformula.type!=1">
						<view class="main_size color_red">高({{goodsInfo.shopformula.size}})</view>
						<view class="bghui radius margin_left2" style="padding: 20rpx 10rpx;">
							<input type="number" style="text-align: center; min-width: 180rpx;max-width: 180rpx;"
								placeholder="請輸入" class="xiaohong" :disabled="heiDisabled" v-model="hei"
								@blur="heiBlur">
						</view>
					</view>
				</view>
				<view class="flexbetween bghui radius mainpadding margin_top">
					<view class="flexleft">
						<view class="hei_text main_size bold">用量：</view>
						<view class="color_red main_size bold" v-text="formulaValue+(goodsInfo.unit==null? '': goodsInfo.unit)"></view>
					</view>
					<view class="" v-show="goodsInfo.goods_sale.length?Number(goodsInfo.goods_sale[is_df].price_j) < Number(subTotal):true">
						<view class="flexleft">
							<view class="hei_text main_size bold">單價：</view>
							<view class="color_red main_size bold">${{djprice}}</view>
						</view>
					</view>
				</view>
				<view class="flexbetween  bghui radius mainpadding margin_top">
					<view class="hei_text main_size bold" v-if="goodsInfo.is_cl==1 && clxzj_value">用量：<text class="xiaohong">{{clxzj_value}}{{goodsInfo.jj_unit}}</text></view>
					<view class="hei_text main_size bold" v-if="!clxzj_value"></view>
					<view class="hei_text main_size bold">小計價格：<text class="xiaohong" v-text="'$'+subTotal"></text></view>
				</view>
				<u-modal :show="clshow" title="處理選擇" confirmText="確認" @confirm="chongzhi" cancelText="關閉"
					@cancel="clshow=false" :showConfirmButton="false">
					<view class="slot-content" style="width: 600rpx;" v-if="goodsInfo.goods_sale.length">
						<scroll-view scroll-y="true" style="height: 300rpx;">
							<view class="flexbetween margin_top" v-for="item in goodsInfo.goods_sale[this.is_df].sale_money" :key="item.id" @click="checkchuli(item)">
								<view class="hei_text main_size bold">用量：<text class="xiaohong" style="margin-right: 50rpx;">{{item.js_num}}{{goodsInfo.jj_unit}}</text>單價：<text class="xiaohong margin_right1">{{item.d_money}}元</text></view>
								<u-icon name="checkmark-circle-fill" color="#999" size="20" v-if="item.id!=clxz_id"></u-icon>
								<u-icon name="checkmark-circle-fill" color="#ffb800" size="20" v-if="item.id==clxz_id"></u-icon>
							</view>
						</scroll-view>
					</view>
				</u-modal>
			</view>
			<view class="flexbetween ffffff mainpadding_top radius">
				<view class="titletext bold hei_text">數量</view>
				<!-- <view class="flexbetween bghui radius" style="padding: 10rpx;">
					<view class="reduceimg" @click="reduceFn"></view>
					<input type="number" style="width: 100rpx; text-align: center;" v-model="num">
					<view class="addimg" @click="addFn"></view>
				</view> -->
				<view class="numberBg" v-if="goodsInfo.is_cl!=1">
					<u-number-box button-size="36" color="#000000" bgColor="#F7F7F7" iconStyle="color: #fff"
						v-model="num"></u-number-box>
				</view>
				<view class="titletext bold hei_text" v-if="goodsInfo.is_cl==1">{{num}}</view>
			</view>
			<view class="ffffff mainpadding_top radius" v-if="sp_attr.length">
				<view class="titletext bold hei_text"> 客戶資料填寫<text style="color: #ff0000;">*</text></view>
				<view class=" margin_top" :class="index+1==sp_attr.length?'':'pdl'" v-for="(item,index) in sp_attr" :key="index">
					<view class="main_size bold hei_text">{{item.name}}</view>
					<input type="text" class="margin_top1" placeholder="請輸入" v-model="item.value"/>
				</view>
			</view>
			<!-- 上傳文件 -->
			<view class="mainpadding_top ffffff radius" v-if="goodsInfo.is_up==1">
				<view class="flexbetween">
					<view class="flexleft">
						<image src="/static/images/index/wenjian.png" style="width: 56rpx;height: 56rpx;" mode="">
						</image>
						<view class="titletext hei_text bold margin_left">上傳文件名及照片</view>
					</view>
					<view class="flexright" v-if="!addimage">
						<!-- <view class="listbtnhuang margin_left2" @click="uploadImg(addimage,addimage_arr,1)">立即上傳</view> -->
						<view class="listbtnhuang margin_left2" @click="upfile">立即上傳</view>
					</view>
					<view class="flexright" v-else>
						<view class="listbtnhuang margin_left2" @click="upfile">已上傳,點擊替換</view>
					</view>
				</view>
			</view>
			<!-- 商品規格一 -->
			<view class="mainpadding_top ffffff radius" style="padding-top: 0;">
				<!-- <view class="titletext bold hei_text">商品規格一</view> -->
				<view class="flexleft flex_wrap">
					<view class="margin_top margin_right guigelable radius" v-for="item in goodsInfo.goods_sku"
						:key="item.id" @click="goSelectGoods(item)">
						{{item.name}}
					</view>
				</view>
			</view>
			<!-- 商品規格一選擇的商品 -->
			<view class="mainpadding_top ffffff radius" style="position: relative;" v-for="(item,index) in secondList.goods"
				:key="item.id">
				<view class="pdl flexleft">
					<view class="fuwulable">{{item.salename}}</view>
					<view class="listleftimg radius margin_right">
						<image class="listleftimg radius" :src="item.logoimage" mode=""></image>
					</view>
					<view style="width: 100%;">
						<view class="hei_text main_size bold">{{item.goods_name}}</view>
						<view class="xiaohui margin_top1">尺寸：{{item.wei}}*{{item.hei}}
							{{item.formulacount}}{{item.size}}
						</view>
						<view class="xiaohui margin_top1" v-if="item.spunatname">規格：{{item.spunatname}}</view>
						<view class="flexbetween margin_top1">
							<view class="text_w color_red bold">${{Number(item.price).toFixed(0)}}</view>
							<view class="text_six color_red">x{{item.num}}</view>
						</view>
					</view>
				</view>
				<view class="flexright margin_top">
					<view class="flexleft" @click="removeOrder(index)">
						<u-icon name="trash" class="margin_right1" color="#777" size="18"></u-icon>
						<view class="text_b color_san">刪除</view>
					</view>
				</view>
			</view>
			<!-- 商品規格二 -->
			<!-- <view class="paddinglr margin_top flexleft">
				<view class="titletext bold hei_text margin_right1">商品規格二</view>
				<view class="text_w color_orange">*</view>
			</view> -->
			<view class="ffffff radius" v-for="(item,index) in spuList" :key="item.id">
				<view class="flexbetween mainpadding" style="background-color: #f8b62a;">
					<view class="titletext hei_text bold">{{item.name}}</view>
					<view class="xiaohei main_size bold" v-if="item.num_b!=0">{{item.fh==1?'必須':'至少'}}選擇{{item.num_b}}個</view>
				</view>
				<view class="mainpadding">
					<view class="flexleft margin_top" :class="i==item.list.length-1?'':'pdl'" v-for="(value,i) in item.list"
						:key="value.id">
						<!-- <view class="fuwulable">236</view> -->
						<view class="listleftimg2 radius margin_right">
							<image class="listleftimg2 radius" :src="value.image" mode=""></image>
						</view>
						<view class="flexbetween flex1">
							<view style="width: 60%;">
								<view class="hei_text main_size bold yihang">{{value.name}}</view>
								<view class="huang_text main_size bold margin_top">
									<text class="text_h color_red margin_right1">${{Number(value.money).toFixed(0)}}</text>
									<!-- <text class="text_e color_six" style="text-decoration: line-through;">$56</text> -->
								</view>
							</view>
							<!-- <view :class="value.isChecked?'checkbox':'nocheckbox'"
								@click="selectSpu(index,value,item.num_b)"></view> -->
								<u-number-box button-size="36" color="#000000" :min="0" bgColor="#F7F7F7" iconStyle="color: #fff"
									v-model="value.num"></u-number-box>
						</view>
					</view>
				</view>
			</view>
			<!-- 備注 -->
			<view class="mainpadding_top ffffff radius">
				<view class="titletext bold hei_text">備注</view>
				<textarea placeholder="請輸入備注信息" class="margin_top huang_text main_size" style="height: 100rpx;"
					v-model="notes"></textarea>
			</view>
		</view>
		<!-- 商品詳情 -->
		<view class="" v-if="goodsInfo.detailsImages_arr.length">
			<view class="titletext bold hei_text flexcenter">商品詳情</view>
			<view class="margin_top">
				<image :src="item" mode="widthFix" style="width: 100%;display: block;"
					@click="lbtpriview(index,goodsInfo.detailsImages_arr)"
					v-for="(item,index) in goodsInfo.detailsImages_arr" :key="index"></image>
			</view>
		</view>
		<!-- 購買須知 -->
		<view class="mainpadding2" >
			<view class="mainpadding_top ffffff radius" v-if="goodsInfo.buy_notice">
				<view class="titletext bold hei_text flexcenter">購買須知</view>
				<view class="margin_top">
					<text class="text_a color_six ">{{goodsInfo.buy_notice}}</text>
				</view>
			</view>
		</view>
		<!-- 出貨須知 -->
		<view class="mainpadding2"  style="padding-bottom: 200rpx;">
			<view class="mainpadding_top ffffff radius" v-if="goodsInfo.notice">
				<view class="titletext bold hei_text flexcenter">出貨須知</view>
				<view class="margin_top">
					<text class="text_a color_six ">{{goodsInfo.notice}}</text>
				</view>
			</view>
		</view>
		<view class="posibottom mainpadding">
			<view class="flexbetween">
				<view class="leftAllprice flexleft mainpadding ffffff">
					<view class="color_ling text_d">合計：</view>
					<text class="totalPrice hong_text">$</text>
					<text class="totalPrice xiaohong" style="font-size: 36rpx;" v-text="money"></text>
				</view>
				<view class="rightsubmit flexcenter mainpadding" @click="confirm">
					<view class="hei_text main_size">確定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				currentNum: 0,
				swiperList: [], //轮播圖
				num: 1,
				is_df: 0,
				goodsInfo: {
					goods_sale: []
				},
				spuList: [], //商品規格二列表
				// weiDisabled: false,
				heiDisabled: true,

				shop_id: uni.getStorageSync("shop_id"),
				goods_id: "", //商品id
				wei: "", //寬
				hei: "", //高
				spunatname: "", //規格2属性名稱
				spunatid: "", //規格2属性id
				num: 1, //數量
				addimage: "", //上傳的圖片
				addimage_arr: "", //上傳的圖片展示
				formulaValue: 0, //公式算出来的值
				notes: "", //備注
				secondList: {
					goods:[]
				}, //二级商品列表
				pageShow: false,
				transferObj: {},
				order_id:"",//訂單id
				selectSpuNum: [], //商品規格2已選擇的規格属性數量
				djprice: 0,
				clxz_id:"",//處理選擇的id
				clxzj_value:"",//處理選擇的計算值
				//處理選擇
				clshow:false,
				sp_attr: []
			}
		},
		watch: {
			wei(newVal) {
				if (newVal) {
					this.heiDisabled = false
				}
			},
			num: {
				handler(newVal) {
					// this.subTotal()
					if (this.goodsInfo.goods_sale.length && this.clxz_id=="") {
						let arr = []
						this.goodsInfo.goods_sale[this.is_df].sale_money.forEach(item => {
							if (Number(item.js_num) <= Number(this.formulaValue * this.num)) {
								arr.push(item.d_money)
							}
						})
						if (arr.length) {
							this.djprice = arr[0]
						} else {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					}
				},
				deep: true
			},
			formulaValue: {
				handler(newval) {
					console.log(newval, 12345);
					if (this.goodsInfo.goods_sale.length && this.clxz_id=="") {
						let arr = []
						this.goodsInfo.goods_sale[this.is_df].sale_money.forEach(item => {
							if (Number(item.js_num) <= Number(newval * this.num)) {
								arr.push(item.d_money)
							}
						})
						if (arr.length) {
							this.djprice = arr[0]
						} else {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					}
				},
				deep: true
			},
			is_df: {
				handler(newval) {
					console.log(1212);
					if(this.goodsInfo.is_cl==0){
						if (this.goodsInfo.goods_sale.length && this.clxz_id=="") {
							this.djprice = this.goodsInfo.goods_sale[this.is_df].sale_money[0].d_money
						}
					} else{
						this.clxz_id=""
						this.clxzj_value=""
					}
				},
				deep: true
			},
			clxz_id:{
				handler(newval) {
					console.log("jinglke");
					if(this.clxz_id=="" && this.goodsInfo.is_cl==1){
						this.clshow = true
					}
				},
				deep: true
			},
		},
		onLoad(options) {
			uni.$on("checkgoods",data=>{
				this.secondList.goods.push(data)
			})
			let data = JSON.parse(decodeURIComponent(options.msg))
			console.log(data, "傳递的數据")
			this.transferObj = data
			this.goods_id = data.goods_id
			this.addimage = data.addimage
			this.addimage_arr = this.imgUrl + data.addimage
			this.wei = data.wei
			this.hei = data.hei
			this.formulaValue = data.formulacount
			this.num = data.num
			this.order_id=data.id
			this.notes=data.notes
			this.spunatdata = JSON.parse(data.spunatdata)
			this.secondList.goods = data.childdata
			this.getInfo()
		},
		onUnload() {
			uni.$off("checkgoods")
		},
		computed: {
			subTotal() { //小計價格
				let end_price = 0
				let value = this.formulaValue * this.djprice * this.num
				console.log(value);
				let price_j = 0
				if (this.goodsInfo.goods_sale.length) {
					price_j = Number(this.goodsInfo.goods_sale[this.is_df].price_j)
				}
				if (value > price_j) {
					end_price = value
				} else {
					end_price = price_j
				}
				return Number(end_price).toFixed(0)
			},
			moneyzhu() { //總價
				let price = 0
				this.spuList.forEach(item => {
					item.list.forEach(value => {
						// if (value.isChecked) {
						// 	price = Number(price) + Number(value.money)
						// }
						if(value.num){
							price = Number(price) + Number(value.money) * value.num
						}
					})
				})
				price = (Number(this.subTotal) + price)
				return price
			},
			money() { //總價
				let price = 0
				this.spuList.forEach(item => {
					item.list.forEach(value => {
						// if (value.isChecked) {
						// 	price = Number(price) + Number(value.money)
						// }
						if(value.num){
							price = Number(price) + Number(value.money) * value.num
						}
					})
				})
				price = (Number(this.subTotal) + price)
				if (this.secondList.goods) {
					this.secondList.goods.forEach(item => {
						price = Number(price) + Number(item.price) * item.num
					})
				}
				return price
			}
		},
		methods: {
			upfile() {
				let _this = this
				uni.chooseFile({
					count: 1,
					type: 'file',
					success(res) {
						console.log(res,"999");
						for (let i = 0; i < res.tempFiles.length; i++) {
							_this.uploadImageService(res.tempFiles[i].path, _this.files)
						}
					}
				})
			},
			uploadImageService(url){
				console.log(url,"999");
				this.http.uploadFile('/api/common/upload', url).then(res => {
					this.addimage = res.url
					this.addimage_arr = res.fullurl
					// upImg.push(res.url)
					// let image_item = res.fullurl;
					// upImgs_arr.push(image_item);
					// console.log(upImg, "upImg")
					// console.log(upImgs_arr, "upImgs_arr")
				}).catch(err => {});
			},
			checkchuli(item){
				this.clxz_id = item.id
				this.clxzj_value = item.js_num
				this.djprice = item.d_money
				this.clshow = false
			},
			
			async getInfo() { //商品詳情
				let _this = this
				let res = await this.http.request('/api/goods/deail', 'POST', {
					goods_id: this.goods_id
				})
				if (res.code == 1) {
					let arr = []
					if (res.data.carouselimages) {
						res.data.carouselimages.split(",").forEach(item => {
							arr.push(this.imgUrl + item)
						})
					}
					this.swiperList = arr
					if(res.data.logoimage){
						res.data.logoimage = this.imgUrl + res.data.logoimage
						this.swiperList.unshift(res.data.logoimage)
					}
					if (res.data.mvfile) {
						this.swiperList.unshift(this.imgUrl + res.data.mvfile)
					}
					let detailsImages_arr = []
					if(res.data.detailsimages){
						res.data.detailsimages.split(",").forEach(item => {
							detailsImages_arr.push(this.imgUrl + item)
						})
					}
					this.$set(res.data, "detailsImages_arr", detailsImages_arr)
					let spuList = []
					res.data.goods_spu.forEach(item => {
						spuList.push({
							id: item.id,
							name: item.name,
							num_b: item.num_b,
							list: [],
							fh:item.fh
						})
					})
					res.data.goods_spunat.forEach(item => {
						item.image = this.imgUrl + item.image
						// let arr = this.spunatid.split(",") 
						// this.$set(item, "isChecked", false)
						this.$set(item, "num", 0)
						console.log(this.spunatdata);
						this.spunatdata.forEach(val=>{
							if(item.id==val.spunatid){
								this.$set(item, "num", val.num)
							}
						})
						spuList.forEach(value => {
							if (item.goods_spu_id == value.id) {
								value.list.push(item)
							}
						})
					})
					this.spuList = spuList
					let sp_attr = []
					if (res.data.sp_attr) {
						res.data.sp_attr.split(",").forEach(item => {
							sp_attr.push({
								name: item,
								value: ""
							})
						})
					}
					this.sp_attr = sp_attr
					this.goodsInfo = res.data
					if(res.data.is_cl==1){
						this.clshow = true
					}
					this.djprice = res.data.goods_sale.length ? res.data.goods_sale[0].sale_money[0].d_money : res.data.price
					this.is_df = this.goodsInfo.goods_sale.findIndex(item => {
						return this.transferObj.salename == item.name
					})
					this.pageShow = true
				} else{
					this.http.toast(res.msg)
					setTimeout(()=>{
						uni.navigateBack(1)
					},1000)
				}
			},
			weiBlur() { //寬失去焦點
				let value = 0
				let weiValue = 0
				let heiValue = 0
				let info = this.goodsInfo.shopformula;
				let goodsInfo = this.goodsInfo;
				// if (!this.hei) {
				// 	return false
				// }
				if (info.type == 0) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					if (goodsInfo.size) {
						let weinumshow = this.ifnumshow(weiValue, goodsInfo.size.split(";"))
						let heinumshow = this.ifnumshow(heiValue, goodsInfo.size.split(";"))
						if (weinumshow && heinumshow) { //如果两個都没有超過的话就正常判断
							if (Number(weiValue) > Number(heiValue)) {
								weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							} else {
								heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							}
			
						}
						if (weinumshow && !heinumshow) { //如果寬度没有超過高度超過了就計算寬度的值
							weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							console.log(1);
						}
						if (!weinumshow && heinumshow) { //如果高度没有超過寬度超過了就計算高度的值
							heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							console.log(2);
						}
					}
					value = eval((weiValue + info.wei_c + heiValue) + info.hei_c + info.numval)
				} else if (info.type == 1) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					value = eval(weiValue + info.hei_c + info.numval)
				} else if (info.type == 3) {
					value = Number(this.wei) > Number(this.hei) ? this.wei : this.hei
				} else if (info.type == 4) {
					value = Number(this.wei) > Number(this.hei) ? this.hei : this.wei
				} else if (info.type == 5) {
					weiValue = (Number(this.wei) / Number(info.wei_b)).toFixed(0) * Number(info.wei_b)
					heiValue = (Number(this.hei) / Number(info.hei_b)).toFixed(0) * Number(info.hei_b)
					value = eval(weiValue + info.wei_c + heiValue + info.hei_c + info.numval)
				}
				console.log(weiValue, "寬度", heiValue, "高度", value, "結果");
				// let pricetwo = value.toFixed(info.num)
				this.formulaValue = (Number(value).toFixed(info.num))>=1?Number(value).toFixed(info.num):1
			},
			ifnumshow(val, arr) {
				let num = 0
				arr.forEach(item => {
					if (Number(val) < Number(item)) {
						num = num + 1
					}
				})
				return num ? true : false
			},
			MaxFn(str, arr) {
				let list1 = []
				let returnnum = 0
				arr.forEach(item => {
					if (Number(str) < Number(item)) {
						list1.push(item)
					}
				})
				returnnum = (Math.min.apply(null, list1))
				return returnnum
			},
			heiBlur() { //高失去焦點
				let value = 0
				let weiValue = 0
				let heiValue = 0
				let info = this.goodsInfo.shopformula
				let goodsInfo = this.goodsInfo;
				if (info.type == 0) {
					weiValue = eval(this.wei + info.wei_a + info.wei_b)
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					if (goodsInfo.size) {
						let weinumshow = this.ifnumshow(weiValue, goodsInfo.size.split(";"))
						let heinumshow = this.ifnumshow(heiValue, goodsInfo.size.split(";"))
						if (weinumshow && heinumshow) { //如果两個都没有超過的话就正常判断
							if (Number(weiValue) > Number(heiValue)) {
								weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							} else {
								heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							}
			
						}
						if (weinumshow && !heinumshow) { //如果寬度没有超過高度超過了就計算寬度的值
							weiValue = this.MaxFn(weiValue, goodsInfo.size.split(";"))
							console.log(1);
						}
						if (!weinumshow && heinumshow) { //如果高度没有超過寬度超過了就計算高度的值
							heiValue = this.MaxFn(heiValue, goodsInfo.size.split(";"))
							console.log(2);
						}
					}
					value = eval((weiValue + info.wei_c + heiValue) + info.hei_c + info.numval)
				} else if (info.type == 2) {
					heiValue = eval(this.hei + info.hei_a + info.hei_b)
					value = eval(heiValue + info.hei_c + info.numval)
				} else if (info.type == 3) {
					value = Number(this.wei) > Number(this.hei) ? this.wei : this.hei
				} else if (info.type == 4) {
					value = Number(this.wei) > Number(this.hei) ? this.hei : this.wei
				} else if (info.type == 5) {
					weiValue = (Number(this.wei) / Number(info.wei_b)).toFixed(0) * Number(info.wei_b)
					heiValue = (Number(this.hei) / Number(info.hei_b)).toFixed(0) * Number(info.hei_b)
					value = eval(weiValue + info.wei_c + heiValue + info.hei_c + info.numval)
				}
				console.log(weiValue, "寬度", heiValue, "高度");
				this.formulaValue = (Number(value).toFixed(info.num))>=1?Number(value).toFixed(info.num):1
			},
			goSelectGoods(item) { //商品規格一選擇商品
				let arr = []
				item.shopclassify_id.split(",").forEach(value => {
					arr.push({
						id: value,
						name: ""
					})
				})
				item.shopclassify_name.split(",").forEach((value, index) => {
					arr[index].name = value
				})
				uni.navigateTo({
					url: "/pages_index/classifyScreenGoods?msg=" + encodeURIComponent(JSON.stringify(arr))
				})
			},
			editGoods(item) { //編輯訂單商品
				// uni.navigateTo({
				// 	url: "/pages_index/goodsInfoEdit?msg=" + encodeURIComponent(JSON.stringify(item))
				// })
				uni.navigateTo({
					url: "/pages_index/goodsInfoEditSecond?msg=" + encodeURIComponent(JSON.stringify(item))
				})
			},
			async removeOrder(index) { //刪除二级商品
				this.secondList.goods.splice(index,1)
			},
			selectSpu(index, value, num_b) { //選擇商品規格二
				value.isChecked = value.isChecked ? false : true
				// if (num_b != 0) {
				// 	let selectNum = this.selectSpuNum[index].selectId.length
				// 	if (selectNum != num_b) {
				// 		this.selectSpuNum[index].selectId.push(value.id)
				// 		value.isChecked = true
				// 	} else {
				// 		let i = this.spuList[index].list.findIndex(item => {
				// 			return item.id == this.selectSpuNum[index].selectId[selectNum - 1]
				// 		})
				// 		this.spuList[index].list[i].isChecked = false
				// 		value.isChecked = true
				// 		this.$set(this.selectSpuNum[index].selectId, selectNum - 1, value.id)
				// 	}
				// } else {
				// 	this.spuList[index].list.forEach(item => {
				// 		item.isChecked = false
				// 	})
				// 	value.isChecked = true
				// }
			},
			confirm() {
				if (!httpRequest.checkIsLogin()) {
					uni.navigateTo({
						url: "/pages/login/login"
					})
					return false
				}
				if(this.num>this.goodsInfo.xd_num && Number(this.goodsInfo.xd_num)!=-1){
					this.http.toast("當前商品限點"+this.goodsInfo.xd_num+"件")
					return false
				}
				if(this.goodsInfo.end_num!=-1){
					if(Number(this.num)>Number(this.goodsInfo.end_num)){
						this.http.toast("當前商品庫存僅剩"+this.goodsInfo.end_num)
						return false
					}
				}
				if (this.goodsInfo.is_size == 1) {
					if(this.goodsInfo.shopformula.type!=2){
						if (!this.wei) {
							this.http.toast("請輸入寬！")
							return false
						}
					}
					if(this.goodsInfo.shopformula.type!=1){
						if (!this.hei) {
							this.http.toast("請輸入高！")
							return false
						}
					}
				}
				if(this.sp_attr.length){
					for (let i = 0; i < this.sp_attr.length; i++) {
						let item = this.sp_attr[i]
						if(item.value==""){
							this.http.toast("請輸入"+item.name)
							return false
						}
					}
				}
				this.getAddOrderGoods()
			},
			async getAddOrderGoods() {
				let spunatdata = []
				for (let i = 0; i < this.spuList.length; i++) {
					let item = this.spuList[i]
					let num = 0
					item.list.forEach(value => {
						if (value.num!=-0) {
							num = num + Number(value.num)
							spunatdata.push({
								spunatid:value.id,
								spunatname:value.name,
								num:value.num
							})
						}
					})
					if(item.fh==1){//等於
						if (num != item.num_b) {
							this.http.toast(item.name + "的規格必選" + item.num_b + "個")
							return false
						}
					}
					if(item.fh==2){//大於等於
						if (num < item.num_b) {
							this.http.toast(item.name + "的規格至少選擇" + item.num_b + "個")
							return false
						}
					}
				}
				let childdata = this.secondList.goods
				childdata.forEach(item=>{
					delete item.goods_name
					delete item.logoimage
				})
				let res = await this.http.request('/api/goods/editGoodsCart', 'POST', {
					id:this.order_id,//訂單id
					wei: this.wei, //寬
					hei: this.hei, //高
					size: this.goodsInfo.unit, //單位
					formulacount: this.formulaValue, //公式計算的值
					salename: this.goodsInfo.goods_sale.length?this.goodsInfo.goods_sale[this.is_df].name:"", //销售類别名稱
					spunatdata: spunatdata, //規格2
					num: this.num, //數量
					price: this.moneyzhu, //價格
					d_price:this.djprice,
					addimage: this.addimage, //上傳的圖片
					type: 0, //0主商品 1子商品
					sp_attr:this.sp_attr,
					childdata
				})
				if (res.code == 1) {
					uni.navigateBack(1)
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}

	.indicator-num {
		padding: 2px 0;
		background-color: rgba(0, 0, 0, 0.35);
		border-radius: 100px;
		width: 35px;
		@include flex;
		justify-content: center;

		&__text {
			color: #FFFFFF;
			font-size: 12px;
		}
	}

	.numberBg {
		background: #F7F7F7;
		padding: 8rpx 6rpx;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}

	.checkbox {
		width: 30rpx;
		height: 30rpx;
		background-image: url("@/static/images/index/trueSelect.png");
		background-size: 100% 100%;
	}

	.nocheckbox {
		width: 30rpx;
		height: 30rpx;
		background-image: url("@/static/images/index/trueNoSelect.png");
		background-size: 100% 100%;
	}

	::v-deep.u-number-box__minus {
		background-color: #EC7AA0 !important;
	}

	::v-deep.u-number-box__plus {
		background-color: #EC7AA0 !important;
	}

	::v-deep.uicon-minus {
		color: #000000 !important;
	}

	::v-deep.uicon-plus {
		color: #000000 !important;
	}

	::v-deep.u-radio-group {
		flex: none !important;
	}

	.mainpadding {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.mainpadding2 {
		padding: 0 30rpx 30rpx;
		box-sizing: border-box;
	}

	.mainpadding_top {
		padding: 30rpx;
		margin-top: 30rpx;
		box-sizing: border-box;
	}

	.margin_top {
		margin-top: 30rpx;
	}

	.margin_right2 {
		margin-right: 20rpx;
	}

	.margin_right {
		margin-right: 30rpx;
	}

	.margin_left2 {
		margin-left: 20rpx;
	}

	.margin_left {
		margin-left: 30rpx;
	}

	.flexcenter {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.flexbetween {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.flexleft {
		display: flex;
		align-items: center;
	}

	.flexright {
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.flex_wrap {
		flex-wrap: wrap;
	}

	.ffffff {
		background-color: #fff;
	}

	.radius {
		border-radius: 10rpx;
	}

	.xiaohui {
		font-size: 24rpx;
		color: #999;
	}

	.xiaohong {
		font-size: 34rpx;
		color: #ff0000;
	}

	.xiaohuang {
		font-size: 24rpx;
		color: #ffb800;
	}

	.hui_text {
		color: #999;
	}

	.huang_text {
		color: #ffb800;
	}

	.hei_text {
		color: #333;
	}

	.titletext {
		font-size: 32rpx;
		font-family: PingFang SC-Medium, PingFang SC;
	}

	.bold {
		font-weight: bold;
	}

	.main_size {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}

	.listleftimg {
		width: 150rpx;
		height: 150rpx;
		position: relative;
	}

	.pdl {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(0, 0, 0, .03);
	}

	.listbtnhuang {
		border-radius: 50rpx;
		padding: 15rpx 30rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF5C00;
		border: 1rpx solid #FF5C00;
	}

	.lableradius {
		border-radius: 10rpx 10rpx 10rpx 0;
		padding: 5rpx 10rpx;
		font-size: 26rpx,
	}

	.neiyong {
		background-color: #fff3e6;
		color: #ffb800;
	}

	/* //合計 */
	.posibottom {
		position: fixed;
		bottom: 30rpx;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}

	.leftAllprice {
		border-radius: 50rpx 0 0 50rpx;
		flex: 6;
	}

	.rightsubmit {
		background-color: #ffb800;
		border-radius: 0 50rpx 50rpx 0;
		flex: 1;
	}

	.fuwulable {
		position: absolute;
		top: 0;
		right: 0;
		border-radius: 0 10rpx 0 10rpx;
		background-color: #fff4e8;
		font-size: 16rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ffb800;
		padding: 5rpx 30rpx;
	}

	.bghui {
		background-color: #f7f7f6;
	}

	.listleftimg2 {
		width: 110rpx;
		height: 110rpx;
	}

	.guigelable {
		background-color: #ffb800;
		color: #fff;
		font-size: 32rpx;
		padding: 15rpx 30rpx;
	}
</style>